package fr.lip6.meta.tools;



//import java.io.File;
//import java.io.IOException;
//import java.util.ArrayList;
import java.util.Iterator;


import org.eclipse.emf.common.util.EList;
//import org.eclipse.emf.common.util.TreeIterator;
import org.eclipse.emf.common.util.URI;

import org.eclipse.emf.ecore.EObject;


//import org.eclipse.emf.ecore.plugin.EcorePlugin;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
//import org.eclipse.emf.ecore.util.EcoreUtil;
//import org.eclipse.emf.ecore.xmi.XMIPlugin;
import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl;
import org.eclipse.emf.ecore.xmi.impl.XMIResourceImpl;

import org.eclipse.gmt.modisco.java.AbstractTypeDeclaration;
import org.eclipse.gmt.modisco.java.BodyDeclaration;
import org.eclipse.gmt.modisco.java.ClassDeclaration;
import org.eclipse.gmt.modisco.java.AssertStatement;
import org.eclipse.gmt.modisco.java.BreakStatement;
import org.eclipse.gmt.modisco.java.CatchClause;
import org.eclipse.gmt.modisco.java.AbstractMethodDeclaration;
import org.eclipse.gmt.modisco.java.Block;
//import org.eclipse.gmt.modisco.java.ConstructorDeclaration;
import org.eclipse.gmt.modisco.java.ConstructorDeclaration;
import org.eclipse.gmt.modisco.java.ConstructorInvocation;
import org.eclipse.gmt.modisco.java.ContinueStatement;
import org.eclipse.gmt.modisco.java.DoStatement;
import org.eclipse.gmt.modisco.java.EmptyStatement;
import org.eclipse.gmt.modisco.java.EnhancedForStatement;
import org.eclipse.gmt.modisco.java.ExpressionStatement;
import org.eclipse.gmt.modisco.java.FieldDeclaration;
import org.eclipse.gmt.modisco.java.ForStatement;
import org.eclipse.gmt.modisco.java.IfStatement;
import org.eclipse.gmt.modisco.java.InterfaceDeclaration;
import org.eclipse.gmt.modisco.java.LabeledStatement;
import org.eclipse.gmt.modisco.java.MethodDeclaration;
import org.eclipse.gmt.modisco.java.Model;
import org.eclipse.gmt.modisco.java.Package;
import org.eclipse.gmt.modisco.java.ReturnStatement;
import org.eclipse.gmt.modisco.java.SingleVariableDeclaration;
import org.eclipse.gmt.modisco.java.Statement;
import org.eclipse.gmt.modisco.java.SuperConstructorInvocation;
import org.eclipse.gmt.modisco.java.SwitchCase;
import org.eclipse.gmt.modisco.java.SynchronizedStatement;
import org.eclipse.gmt.modisco.java.ThrowStatement;
import org.eclipse.gmt.modisco.java.TryStatement;
import org.eclipse.gmt.modisco.java.TypeAccess;
import org.eclipse.gmt.modisco.java.TypeDeclarationStatement;
import org.eclipse.gmt.modisco.java.UnresolvedLabeledStatement;
import org.eclipse.gmt.modisco.java.VariableDeclarationStatement;
import org.eclipse.gmt.modisco.java.WhileStatement;
import org.eclipse.gmt.modisco.java.emf.JavaPackage;
//import org.eclipse.gmt.modisco.java.emf.impl.ClassDeclarationImpl;
import org.eclipse.gmt.modisco.java.emf.impl.ConstructorDeclarationImpl;
import org.eclipse.gmt.modisco.java.emf.impl.FieldDeclarationImpl;
import org.eclipse.gmt.modisco.java.emf.impl.MethodDeclarationImpl;
//import org.eclipse.uml2.uml.resource.XMI212UMLResource;

import fr.lip6.meta.ple.generation.strategy.GenerateFromXmiStrategy;
//import fr.lip6.meta.ple.plextraction.Extract;

import artefact.generic.Artefact;
import artefact.generic.ConstructionPrimitive;

import artefact.umlClassDiagram.ClassDiagram;
import artefact.umlClassDiagram.CreateAttribute;
import artefact.umlClassDiagram.CreateClass;
import artefact.umlClassDiagram.CreateGeneralization;
import artefact.umlClassDiagram.CreateInterface;
import artefact.umlClassDiagram.CreateOperation;
import artefact.umlClassDiagram.CreateOperationRefinement;
import artefact.umlClassDiagram.CreatePackage;
import artefact.umlClassDiagram.CreateStatement;
import artefact.umlClassDiagram.StatementName;
import artefact.umlClassDiagram.impl.CreateStatementImpl;
import artefact.umlClassDiagram.impl.UmlClassDiagramFactoryImpl;

//import java.util.*;
//import java.util.logging.Level;
//import java.util.logging.LogRecord;

/**
 *
 * Cette classe charge un "Model" depuis un fichier XMI
 *
 */

public class ModiscoJavaModelLoader {

	Artefact artefact;
	boolean first = false;
	String lien;

	ConstructionPrimitive currentPrimitive = null;

	// doc a rajouter
	CreateStatement currentCreateStatement ;

	UmlClassDiagramFactoryImpl factory;
	ClassDiagram product;

	protected static ModiscoJavaModelLoader instance;

	public  ModiscoJavaModelLoader() {
		factory = new UmlClassDiagramFactoryImpl();
		product = factory.createClassDiagram();

	}

	public static ModiscoJavaModelLoader getInstance() {
		if (instance == null) {
			instance = new ModiscoJavaModelLoader();
		}
		return instance;
	}

	public static Model loadModiscoJavaModel(String path) {

		Resource resource = loadJavaModel(path);
		//System.out.println(resource.getContents().size());

		Model model = (Model) resource.getContents().get(0);

		return model;

	}

	public static EObject loadModiscoJavaEoBject(String path) {

		Resource resource = loadJavaModel(path);

		EObject model = resource.getContents().get(0);

		System.out.println("class"+model.eClass().getName());
		return model;




	}

	public static Resource loadJavaModel(String path) {





		Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("*",
				new XMIResourceFactoryImpl());


		ResourceSet rs = new ResourceSetImpl();


		URI uri = URI.createFileURI(path);
		System.out.println(uri);
		System.out.println("---------------------------------------------------------");
		rs.getPackageRegistry().put(JavaPackage.eNS_URI,
				JavaPackage.eINSTANCE);
		XMIResourceImpl resource = (XMIResourceImpl) rs.getResource(uri, true);


		return resource;
	}



	public void createArtefact(Model model, String lien) {
		this.lien = lien;
		//for packages
		// on recupere lensemble des package du produit de lien 'lien'
		Iterator<Package> packages = model.getOwnedElements().iterator();
		UmlClassDiagramFactoryImpl factory = new UmlClassDiagramFactoryImpl();
		/*ClassDiagram productCD1 = */factory.createClassDiagram();

		// pour chaque package du lien recuperer on boucle
		while (packages.hasNext()) {
			Package p = packages.next();

			if (!p.isProxy()) {        
				if (lien.contains("bank4")) {
					generatePackage(p);
				} else {
					// on recupere le sous package concercant le package principal
					GenerateFromXmiStrategy.packages.clear();
					GenerateFromXmiStrategy.readsubpackage(p, "");
					for(Package package1 : GenerateFromXmiStrategy.packages) {
						generatePackage(package1);
					}
				}
			}
		}
		//Artefact2File.print(product, "test1.txt");
	}

	private void generatePackage(Package p) {
		if(!p.getName().contains("java"))
		{
			CreatePackage createPackage=factory.createCreatePackage();
			System.out.println("Createpackage("+p.getName()+","+lien+");");
			createPackage.setName(p.getName());
			createPackage.setLien(lien);
			if(currentPrimitive==null)
			{
				currentPrimitive=createPackage;
				product.setFirst(createPackage);
			}
			else
			{
				currentPrimitive.setNext(createPackage);
				currentPrimitive=createPackage;
			}


			Iterator<AbstractTypeDeclaration> classs = p.getOwnedElements().iterator();
			while (classs.hasNext())
			{
				AbstractTypeDeclaration ab=classs.next();
				if(ab instanceof ClassDeclaration )
				{
					ClassDeclaration c=(ClassDeclaration) ab;
					generateClass(c);

				}
				if(ab instanceof InterfaceDeclaration)
				{
					InterfaceDeclaration intf=(InterfaceDeclaration) ab;   
					generateInterface(intf);
				}
			}
		}
	}

	private void generateClass(ClassDeclaration c) {
		// recuperation dune classe heriter
		TypeAccess tp = c.getSuperClass();
		String owner = c.getPackage().getName();
		System.out.println("CreateClass("+c.getName()+","+owner+","+lien+")");
		CreateClass createClass = factory.createCreateClass();

		createClass.setName(c.getName());
		createClass.setOwener(owner);
		createClass.setLien(lien);

		if(tp == null) {
			if (currentPrimitive == null) {
				currentPrimitive = createClass;
				product.setFirst(createClass) ;  
			} else {
				currentPrimitive.setNext(createClass);
				currentPrimitive = createClass;
			}
		} else if(tp != null) {
			System.err.println("CreateGeneralization("+c.getName()+","+tp.getType().getName()+","+lien+")");
			CreateGeneralization creategeneration = factory.createCreateGeneralization();

			creategeneration.setSuper(tp.getType().getName());
			creategeneration.setSub(c.getName());
			creategeneration.setLien(lien+"::"+c.getPackage().getName());

			if(currentPrimitive == null) {
				currentPrimitive = creategeneration;
				product.setFirst(creategeneration);
			} else {
				currentPrimitive.setNext(creategeneration);
				currentPrimitive=creategeneration;
			}
		}

		EList<BodyDeclaration> bodys = c.getBodyDeclarations();

		for(BodyDeclaration bo : bodys) {
			if(bo instanceof FieldDeclarationImpl) {
				FieldDeclarationImpl fd=(FieldDeclarationImpl) bo;	
				generateAttribute(fd);
			} else if(bo instanceof MethodDeclarationImpl || bo instanceof ConstructorDeclarationImpl) {
				generateOperation(bo);
			}
		}
	}

	private void generateInterface(InterfaceDeclaration c)
	{
		String owner=c.getPackage().getName();
		System.out.println("CreateInterface("+c.getName()+","+owner+","+lien+")");
		CreateInterface createClass = factory.createCreateInterface();
		createClass.setName(c.getName());
		createClass.setOwner(owner);
		createClass.setLien(lien);


		{

			if (currentPrimitive==null){
				currentPrimitive=createClass;
				product.setFirst(createClass) ;  
			}

			else {


				currentPrimitive.setNext(createClass);
				currentPrimitive=createClass;
			}
		}  


		EList<BodyDeclaration> bodys=c.getBodyDeclarations();
		for(BodyDeclaration bo:bodys)
		{


			if(bo instanceof MethodDeclarationImpl || bo instanceof ConstructorDeclarationImpl)
			{
				generateOperation(bo);
			}
		}
	}


	private void generateAttribute(FieldDeclaration f) {
		String owner=f.getAbstractTypeDeclaration().getName();
		System.out.println("CreareAttribute("+f.getFragments().get(0).getName()+"," +owner+","+lien+")");

		CreateAttribute createAttribute = factory.createCreateAttribute();
		createAttribute.setName(f.getFragments().get(0).getName());
		createAttribute.setOwner(owner);
		createAttribute.setLien(lien+"::"+f.getAbstractTypeDeclaration().getPackage().getName());

		if (currentPrimitive == null) {
			currentPrimitive=createAttribute;
			product.setFirst(createAttribute);
		} else {
			currentPrimitive.setNext(createAttribute);
			currentPrimitive=createAttribute;
		}
	}

	private void generateOperation(BodyDeclaration bodyDecl) {

		if (!(bodyDecl instanceof MethodDeclaration)) {
			String owner = bodyDecl.getAbstractTypeDeclaration().getName();
			CreateOperation createOperation = factory.createCreateOperation();
			String parameters = "";
			EList<SingleVariableDeclaration> paramsList = null;
			if (bodyDecl instanceof ConstructorDeclaration)
				paramsList = ((ConstructorDeclaration) bodyDecl).getParameters();
			if (paramsList != null) {
				for(SingleVariableDeclaration param : paramsList) {
					parameters += param.getType().getType().getName()+",";
				}
			}
			parameters = "(" + parameters.substring(0, parameters.length() < 2 ? 0 : parameters.length()-1) + ")";
			createOperation.setName(bodyDecl.getName());
			createOperation.setOwener(owner);
			createOperation.setLien(
					lien
					+	"::"+bodyDecl.getAbstractTypeDeclaration().getPackage().getName()
					+	"::"+parameters	);

			System.out.println("CreateConstructorOperation("+bodyDecl.getName()+","+owner+","+createOperation.getLien()+")");


			if (currentPrimitive==null){
				currentPrimitive=createOperation;
				product.setFirst(createOperation) ;  
			} 
			else {
				currentPrimitive.setNext(createOperation);
				currentPrimitive=createOperation;
			}	

			// Rajouter
			ConstructorDeclarationImpl cd = (ConstructorDeclarationImpl) bodyDecl;
			if(cd.getBody()!=null)
				generateStatement(cd.getBody(),cd,createOperation);
			///////////////////////////////////////////////////////////////////////////////


		} 
		else {
			MethodDeclarationImpl md = (MethodDeclarationImpl) bodyDecl;
			String parameters = "";
			EList<SingleVariableDeclaration> paramsList = null;

			paramsList = md.getParameters();

			if (paramsList != null) {
				for(SingleVariableDeclaration param : paramsList) {
					parameters += param.getType().getType().getName()+",";
				}
			}

			parameters = "(" + parameters.substring(0, parameters.length() < 2 ? 0 : parameters.length()-1) + ")";

			if (md.getRedefinedMethodDeclaration() == null) {
				String owner = bodyDecl.getAbstractTypeDeclaration().getName();
				CreateOperation createOperation = factory.createCreateOperation();

				createOperation.setName(bodyDecl.getName());
				createOperation.setOwener(owner);
				createOperation.setLien(
						lien
						+	"::"+bodyDecl.getAbstractTypeDeclaration().getPackage().getName()
						+	"::"+parameters	);

				System.out.println("CreateOperation("+bodyDecl.getName()+","+owner+","+createOperation.getLien()+")");

				if (currentPrimitive == null) {
					currentPrimitive = createOperation;
					product.setFirst(createOperation) ;  
				} 
				else {
					currentPrimitive.setNext(createOperation);
					currentPrimitive = createOperation;
				}

				// Rajouter 
				if(md.getBody()!=null)
					generateStatement(md.getBody(),md,createOperation);
				////////////////////////////////////////////////////////////
			} 
			else {
				String owner = bodyDecl.getAbstractTypeDeclaration().getName();

				CreateOperationRefinement createOperation = factory.createCreateOperationRefinement();
				createOperation.setName(bodyDecl.getName());
				createOperation.setOwner(owner);
				createOperation.setSuper((md.getRedefinedMethodDeclaration().getAbstractTypeDeclaration().getName()));
				createOperation.setLien(
						lien
						+	"::"+bodyDecl.getAbstractTypeDeclaration().getPackage().getName()
						+	"::"+parameters	);

				System.out.println("CreateRefinementOperation("+bodyDecl.getName()+","+owner+","+createOperation.getLien()+")");


				if (currentPrimitive == null) {
					currentPrimitive = createOperation;
					product.setFirst(createOperation);
				} 
				else {
					currentPrimitive.setNext(createOperation);
					currentPrimitive = createOperation;
				}

				// Rajouter 

				if(md.getBody()!=null){
					generateStatement(md.getBody(),md,createOperation);
				}

				////////////////////////////////////////////////////////////

			}
		}


	}


	// Rajouter
	private void addCreateStatementIntoCreateOperation(ConstructionPrimitive cp, CreateStatement statementToAdd){

		if( (cp instanceof CreateOperation && ((CreateOperation)cp).getBlock()==null) ){
			((CreateOperation)cp).setBlock(statementToAdd);
			currentCreateStatement=statementToAdd;
			System.out.println(currentCreateStatement);
		}
		if( (cp instanceof CreateOperationRefinement && ((CreateOperationRefinement)cp).getBlock()==null) ){
			((CreateOperationRefinement)cp).setBlock(statementToAdd);
			currentCreateStatement=statementToAdd;
			System.out.println(currentCreateStatement);
		}
		else {
			System.out.println(currentCreateStatement);
			currentCreateStatement.setNext(statementToAdd);
			currentCreateStatement=statementToAdd;
		}
	}

	// Rajouter 
	private void generateStatement(Statement s, BodyDeclaration bd, ConstructionPrimitive owner){

		CreateStatement csi = factory.createCreateStatement();
		csi.setOwnerClass(bd.getAbstractTypeDeclaration().getName());
		csi.setOwnerOperation(bd.getName());
		csi.setOwnerBlock(owner);
		csi.setLien(lien);


		if( s instanceof Block){
			System.out.println("CreateBlock("+csi.getOwnerClass()+","+csi.getOwnerOperation()+","+csi.getLien()+")");
			csi.setStatementName(StatementName.Block);
			addCreateStatementIntoCreateOperation(owner, csi);

			for(Statement st : ((Block)s).getStatements() )
				generateStatement(st,bd,csi);

		}
		// A faire
		else if(s instanceof AssertStatement){
			System.out.println("CreateAssertStatement("+csi.getOwnerClass()+","+csi.getOwnerOperation()+","+csi.getLien()+")");
			csi.setStatementName(StatementName.AssertStatement);
			addCreateStatementIntoCreateOperation(owner, csi);
		}
		// A faire
		else if(s instanceof BreakStatement){
			System.out.println("CreateBreakStatement("+csi.getOwnerClass()+","+csi.getOwnerOperation()+","+csi.getLien()+")");
			csi.setStatementName(StatementName.BreakStatement);
			addCreateStatementIntoCreateOperation(owner, csi);
		}
		else if(s instanceof CatchClause){
			if( ((CatchClause)s).getBody() !=null ){
				System.out.println("CreateCatchClause("+csi.getOwnerClass()+","+csi.getOwnerOperation()+","+csi.getLien()+")");
				csi.setStatementName(StatementName.CatchClause);
				addCreateStatementIntoCreateOperation(owner, csi);
				generateStatement(((CatchClause)s).getBody(),bd,csi);
			}
		}
		else if(s instanceof ConstructorInvocation){
			System.out.println("CreateConstructorInvocation("+csi.getOwnerClass()+","+csi.getOwnerOperation()+","+csi.getLien()+")");
			csi.setStatementName(StatementName.ConstructorInvocation);
			addCreateStatementIntoCreateOperation(owner, csi);
		}
		else if(s instanceof ContinueStatement){
			System.out.println("CreateContinueStatement("+csi.getOwnerClass()+","+csi.getOwnerOperation()+","+csi.getLien()+")");
			csi.setStatementName(StatementName.ContinueStatement);
			addCreateStatementIntoCreateOperation(owner, csi);
		}
		else if(s instanceof DoStatement){
			if( ((DoStatement)s).getBody()!=null ){
				System.out.println("CreateDoStatement("+csi.getOwnerClass()+","+csi.getOwnerOperation()+","+csi.getLien()+")");
				csi.setStatementName(StatementName.DoStatement);
				addCreateStatementIntoCreateOperation(owner, csi);
				generateStatement(((DoStatement)s).getBody(), bd, csi);
			}
		}
		else if(s instanceof EnhancedForStatement){
			if( ((EnhancedForStatement)s).getBody()!=null ){
				System.out.println("CreateEnhancedForStatement("+csi.getOwnerClass()+","+csi.getOwnerOperation()+","+csi.getLien()+")");
				csi.setStatementName(StatementName.EnhancedForStatement);
				addCreateStatementIntoCreateOperation(owner, csi);
				generateStatement(((EnhancedForStatement)s).getBody(), bd, csi);
			}
		}
		else if(s instanceof ExpressionStatement){
			System.out.println("CreateExpressionStatement("+csi.getOwnerClass()+","+csi.getOwnerOperation()+","+csi.getLien()+")");
			csi.setStatementName(StatementName.ExpressionStatement);
			addCreateStatementIntoCreateOperation(owner, csi);
		}
		else if(s instanceof ForStatement){
			if( ((ForStatement)s).getBody()!=null ){
				System.out.println("CreateForStatement("+csi.getOwnerClass()+","+csi.getOwnerOperation()+","+csi.getLien()+")");
				csi.setStatementName(StatementName.ForStatement);
				addCreateStatementIntoCreateOperation(owner, csi);
				generateStatement(((ForStatement)s).getBody(), bd, csi);
			}

		}
		else if(s instanceof IfStatement){
			System.out.println("CreateIfStatement("+csi.getOwnerClass()+","+csi.getOwnerOperation()+","+csi.getLien()+")");
			csi.setStatementName(StatementName.IfStatement);
			addCreateStatementIntoCreateOperation(owner, csi);
			generateStatement( ((IfStatement)s).getThenStatement(), bd,csi );

			if( ((IfStatement)s).getElseStatement()!=null ){

				CreateStatement csi2 = factory.createCreateStatement();
				csi2.setOwnerClass(bd.getAbstractTypeDeclaration().getName());
				csi2.setOwnerOperation(bd.getName());
				csi2.setOwnerBlock(owner);
				csi2.setLien(lien);

				System.out.println("CreateElseStatement("+csi2.getOwnerClass()+","+csi2.getOwnerOperation()+","+csi2.getLien()+")");
				csi2.setStatementName(StatementName.ElseStatement);
				addCreateStatementIntoCreateOperation(owner, csi2);
				generateStatement( ((IfStatement)s).getElseStatement(), bd,csi2 );
			}


		}
		else if(s instanceof LabeledStatement){
			if( ((LabeledStatement)s).getBody()!=null ){
				System.out.println("CreateLabeledStatement("+csi.getOwnerClass()+","+csi.getOwnerOperation()+","+csi.getLien()+")");
				csi.setStatementName(StatementName.LabeledStatement);
				addCreateStatementIntoCreateOperation(owner, csi);
				generateStatement(((LabeledStatement)s).getBody(), bd, csi);
			}
		}
		else if(s instanceof ReturnStatement){
			System.out.println("CreateReturnStatement("+csi.getOwnerClass()+","+csi.getOwnerOperation()+","+csi.getLien()+")");
			csi.setStatementName(StatementName.ReturnStatement);
			addCreateStatementIntoCreateOperation(owner, csi);
		}
		else if(s instanceof SuperConstructorInvocation){
			System.out.println("CreateSuperConstructorInvocation("+csi.getOwnerClass()+","+csi.getOwnerOperation()+","+csi.getLien()+")");
			csi.setStatementName(StatementName.SuperConstructorInvocation);
			addCreateStatementIntoCreateOperation(owner, csi);
		}
		else if(s instanceof SwitchCase){
			System.out.println("CreateSwitchCase("+csi.getOwnerClass()+","+csi.getOwnerOperation()+","+csi.getLien()+")");
			csi.setStatementName(StatementName.SwitchCase);
			addCreateStatementIntoCreateOperation(owner, csi);
		}
		else if(s instanceof SynchronizedStatement){
			if( ((SynchronizedStatement)s).getBody()!=null ){
				System.out.println("CreateSynchronizedStatement("+csi.getOwnerClass()+","+csi.getOwnerOperation()+","+csi.getLien()+")");
				csi.setStatementName(StatementName.SynchronizedStatement);
				addCreateStatementIntoCreateOperation(owner, csi);
				generateStatement( ((SynchronizedStatement)s).getBody(), bd,csi );
			}
		}
		else if(s instanceof ThrowStatement){
			System.out.println("CreateThrowStatement("+csi.getOwnerClass()+","+csi.getOwnerOperation()+","+csi.getLien()+")");
			csi.setStatementName(StatementName.ThrowStatement);
			addCreateStatementIntoCreateOperation(owner, csi);
		}
		else if(s instanceof TryStatement){
			if( ((TryStatement)s).getBody()!=null ){
				System.out.println("CreateTryStatement("+csi.getOwnerClass()+","+csi.getOwnerOperation()+","+csi.getLien()+")");
				csi.setStatementName(StatementName.TryStatement);
				addCreateStatementIntoCreateOperation(owner, csi);
				generateStatement( ((TryStatement)s).getBody(), bd,csi );
			}
		}
		else if(s instanceof TypeDeclarationStatement){
			System.out.println("CreateTypeDeclarationStatement("+csi.getOwnerClass()+","+csi.getOwnerOperation()+","+csi.getLien()+")");
			csi.setStatementName(StatementName.TypeDeclarationStatement);
			addCreateStatementIntoCreateOperation(owner, csi);
		}
		else if(s instanceof UnresolvedLabeledStatement){
			System.out.println("CreateUnresolvedLabeledStatement("+csi.getOwnerClass()+","+csi.getOwnerOperation()+","+csi.getLien()+")");
			csi.setStatementName(StatementName.UnresolvedLabeledStatement);
			addCreateStatementIntoCreateOperation(owner, csi);
		}
		else if(s instanceof VariableDeclarationStatement){
			System.out.println("CreateVariableDeclarationStatement("+csi.getOwnerClass()+","+csi.getOwnerOperation()+","+csi.getLien()+")");
			csi.setStatementName(StatementName.VariableDeclarationStatement);
			addCreateStatementIntoCreateOperation(owner, csi);
		}
		else if(s instanceof WhileStatement){
			if( ((WhileStatement)s).getBody()!=null ){
				System.out.println("CreateWhileStatement("+csi.getOwnerClass()+","+csi.getOwnerOperation()+","+csi.getLien()+")");
				csi.setStatementName(StatementName.WhileStatement);
				addCreateStatementIntoCreateOperation(owner, csi);
				generateStatement( ((WhileStatement)s).getBody(), bd,csi );
			}
		}


	}


	public ClassDiagram getProduct() {
		return product;
	}


	public void setProduct(ClassDiagram product) {
		this.product = product;
	}
}